package org.come.control;

import org.come.Jpanel.TestPetJpanel;
import org.come.action.FromServerAction;
import org.come.entity.RoleSummoning;
import org.come.until.GsonUtil;
import org.come.until.UserMessUntil;

import com.tool.role.RoleData;

public class PetFunctionControl implements FromServerAction {

	@Override
	public void controlMessFromServer(String mes, String type) {

		RoleSummoning roleSummoning = GsonUtil.getGsonUtil().getgson().fromJson(mes, RoleSummoning.class);
		petOperation(roleSummoning);

	}

	/**
	 * 添加召唤兽/修改召唤兽信息
	 */
	public void petOperation(RoleSummoning roleSummoning) {

		// RoleSummoning roleSummoning = GsonUtil.getGsonUtil().getgson().fromJson(mes, RoleSummoning.class);
		for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
			// 判断找到这个召唤兽，并修改它的信息
			if (UserMessUntil.getPetListTable().get(i).getSid().compareTo(roleSummoning.getSid()) == 0) {
				UserMessUntil.getPetListTable().set(i, roleSummoning);
				return;
			}
		}
		UserMessUntil.getPetListTable().add(roleSummoning);
		// 刷新召唤兽面板
		TestPetJpanel.showListModel(UserMessUntil.getPetListTable(), RoleData.getRoleData().getLoginResult().getSummoning_id());
    }
}
